<template>
  <div class="case-query-page">
    <div class="title" slot="header">
      <span class="text">财物列表</span>
      
      <head-btns ref="btns" @add="add" @mod="mod" @del="del" /> 
       <!-- <el-button  type="danger" style="float:right" @click="del" icon="el-icon-delete">删除</el-button> -->
       <!-- <el-button  type="success" style="float:right" @click="mod" icon="el-icon-edit">修改</el-button> -->
      <!-- <el-button   type="primary" style="float:right" @click="add" icon="el-icon-circle-plus">添加</el-button> -->
    </div>
    <list-table ref="listTable" @selected="selected" />
    <edit-form :dept="dept" v-model="editFormVisible" @submit="reloadData"/>
  </div>
</template>
<script>
import ListTable from "@/views/comps/zhzf/list-table";
import CustBtnCol from "@/views/comps/zhzf/list-table-col-btn";
import utils from "@/assets/utils/zhzf-util";
import dictCache from "@/assets/utils/cache-dict-util";
import casePropertyApi from "@/api/system/caseProperty";
import ListSearch from "@/views/comps/zhzf/list-search";
import HeadBtns from "@/views/comps/zhzf/head-btns";

import { mapState, mapMutations } from "vuex";
import tabPageMinxin from "@/assets/minxin/tag-page";
import editForm from "./editForm";
export default {
  mixins: [tabPageMinxin],
  components: { HeadBtns, ListSearch, ListTable, CustBtnCol ,editForm},
  data() {
    return {
      columns: [
        { title: "财物名称", key: "name",  sortable: "true" },
        { title: "财物数量", key: "num",  sortable: "true" },
        { title: "财物描述", key: "remark", sortable: "true" },

        /* {
          title: "操作",
          key: "op",
          component: {
            name: CustBtnCol,
            props: {
              items: [
                { text: "财物登记", emit: "show-detail" },
              ]
            }
          }
        } */
      ],
      dept: {},
      editFormVisible:false,
      selectedRow:[]
    };
  },
  computed: {},
  mounted() {
   /*  this.$bus.$off("show-detail").$on("show-detail", res => {
      this.dept.caseId = res.caseAccessId;
       this.editFormVisible = true;
    }); */
    this.initBtn();
    this.initPage();
  },
  methods: {
    ...mapMutations({
      pageInit: "d2admin/page/init"
    }),
    searchParamChange(query) {
      //console.log(query);
    },
    initBtn(){
      this.$refs.btns.setBtnList([
        {url: "add", name: "添加", icon: "fa fa-plus", type: "", visible:1,color: ""},
        {url: "mod", name: "修改", icon: "fa fa-edit", type: "", visible:1,color: ""},
        {url: "del", name: "删除", icon: "fa fa-trash", type: "",visible:1, color: ""}
      ])
    },
    selected(rows) {
       this.selectedRow = rows;
    },
    async initPage() {
      await this.$refs.listTable.initPage({
        method: casePropertyApi.pageList,
        cols: this.columns,
        param: { caseId: this.$route.params.row.caseAccessId }
      });
    },
    async reloadData() {
      await this.$refs.listTable.reloadData({
          caseId: this.$route.params.row.caseAccessId 
      });
    },
    add() {
      this.dept.caseId = this.$route.params.row.caseAccessId;
     this.editFormVisible = true;
    },
    mod() {
       if (this.selectedRow.length == 1) {
        this.dept = this.selectedRow[0];
        this.editFormVisible = true;
      } else {
        utils.showTips("请选择一行数据");
        return;
      }
    },
    del() {
      if ( this.selectedRow.length == 0) {
        utils.showTips("请选择要删除的数据", false);
        return;
      }
      let delIds = [];
        this.selectedRow.map(item => {
          delIds.push(item.id);
        });
      this.$confirm("确认删除？", "确认信息", {
        distinguishCancelAndClose: true,
        confirmButtonText: "删除",
        cancelButtonText: "取消"
      }).then(() => {
        this.submitDel(delIds);
      }).catch(()=>{});
    },
    async submitDel(ids) {
      await casePropertyApi.del(ids);
      await this.reloadData();
    }
  }
};
</script>
<style lang="scss">
</style>
